package com.example.bookstore.controller;

import com.example.bookstore.common.api.CommonResult;
import com.example.bookstore.mbg.model.Manager;
import com.example.bookstore.mbg.model.User;
import com.example.bookstore.service.ManagerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author: rain
 * @date: 2020/5/12 10:35
 * @description:
 */

@Api(tags = "ManagerController",description = "管理员接口")
@Controller
@RequestMapping("/Manager")
public class ManagerController {

    @Autowired
    private ManagerService managerService;


    @ApiOperation("登录")
    @RequestMapping(value = "/login", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult register(@RequestParam String managerid,
                                 @RequestParam String password) {
        return managerService.login(managerid,password);
    }


    @RequestMapping(value = "/deleteCommentByDealId", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult deleteCommentByDealId(@RequestParam String Dealid){
        managerService.deleteCommentByDealId(Dealid);
        return CommonResult.success(Dealid,"删除成功");
    }

    @RequestMapping(value = "/ModifyUserInformation", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult ModifyUserInformation(@RequestParam String userid,
                                          @RequestParam String username,
                                          @RequestParam String password,
                                          @RequestParam String gender,
                                          @RequestParam String telephone,
                                          @RequestParam String email) {
        User user = new User();
        user.setEmail(email);
        user.setTelephone(telephone);
        user.setGender(gender);
        user.setPassword(password);
        user.setUsername(username);
        user.setUserid(userid);

        return managerService.ModifyUserInformation(user);
    }

    @RequestMapping(value = "/AddBook", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult AddBook(String bookid,String bname,String Descri,String author,String Press,double price,String url,int num){
        return managerService.AddBook(bookid,bname,Descri,author,Press,price,url,num);
    }

    @RequestMapping(value = "/DeleteBookByName", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult DeleteBookByName(String bname){
        return managerService.DeleteBookByName(bname);
    }

    @RequestMapping(value = "/ModifyBook", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult ModifyBook(String bookid,String bname,String Descri,String author,String Press,double price,String url,int num){
        return managerService.ModifyBook(bookid,bname, Descri, author, Press, price, url, num);
    }


    @RequestMapping(value = "/AddNumInBook", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult AddNumInBook(String bookid,String bookname,int num)
    {
        return managerService.AddNumInBook(bookid, bookname, num);
    }
}
